package function;

import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import UserDatabase.Bill;
import UserDatabase.BillDatabase;

public class UpdateAllBillFrame extends JFrame{

	private JLabel l_wbill,l_pbill,l_hbill,l_water,l_electricity,l_gas;
	private JTextField t_wbill,t_pbill,t_hbill,t_water,t_electricity,t_gas;
	private JButton b_confirm,b_reset;
	
	BillDatabase b = new BillDatabase();
	String SQL;
	
	public UpdateAllBillFrame() {
		this.setSize(500,300);
		this.setTitle("更新所有业主费用");
		this.setLocation(600,300);
		init();
		this.setVisible(true);
		
	}
	
	public void init() {
		Font fontB = new Font("宋体",Font.BOLD,16);
		l_water = new JLabel("增收水费为",JLabel.CENTER);
		l_water.setFont(fontB);
		l_electricity = new JLabel("增收电费为",JLabel.CENTER);
		l_electricity.setFont(fontB);
		l_gas = new JLabel("增收燃气为",JLabel.CENTER);
		l_gas.setFont(fontB);
		l_wbill = new JLabel("增收取暖费为",JLabel.CENTER);
		l_wbill.setFont(fontB);
		l_pbill = new JLabel("增收物业费为",JLabel.CENTER);
		l_pbill.setFont(fontB);
		l_hbill = new JLabel("增收房租为",JLabel.CENTER);
		l_hbill.setFont(fontB);
		
		t_water = new JTextField();
		t_water.setFont(fontB);
		t_water.setText("0");
		
		t_electricity = new JTextField();
		t_electricity.setFont(fontB);
		t_electricity.setText("0");
		
		t_gas = new JTextField();
		t_gas.setFont(fontB);
		t_gas.setText("0");
		
		t_wbill = new JTextField();
		t_wbill.setFont(fontB);
		t_wbill.setText("0");
		
		t_pbill = new JTextField();
		t_pbill.setFont(fontB);
		t_pbill.setText("0");
		
		t_hbill = new JTextField();
		t_hbill.setFont(fontB);
		t_hbill.setText("0");
		
		b_confirm = new JButton("确认");
		b_confirm.setFont(fontB);
		b_confirm.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				int water = Integer.parseInt(t_water.getText());
				int electricity = Integer.parseInt(t_electricity.getText());
				int gas = Integer.parseInt(t_gas.getText());
				int wbill = Integer.parseInt(t_wbill.getText());
				int pbill = Integer.parseInt(t_pbill.getText());
				int hbill = Integer.parseInt(t_hbill.getText());
				Bill bill = new Bill(water,electricity,gas,wbill,pbill,hbill);
				b.update_All(bill);
				JPanel f = new JPanel();
				JOptionPane.showMessageDialog(f,"操作成功,请刷新后查看!","提示框",JOptionPane.WARNING_MESSAGE);
				setVisible(false);
			}
			
		});
		b_reset = new JButton("重置");
		b_reset.setFont(fontB);
		b_reset.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				t_water.setText("");
				t_electricity.setText("");
				t_gas.setText("");
				t_wbill.setText("");
				t_pbill.setText("");
				t_hbill.setText("");
			}

		});
		
		JPanel p =new JPanel();
		p.setLayout(new GridLayout(7,2,5,5));
		p.add(l_water);
		p.add(t_water);
		p.add(l_electricity);
		p.add(t_electricity);
		p.add(l_gas);
		p.add(t_gas);
		p.add(l_wbill);
		p.add(t_wbill);
		p.add(l_pbill);
		p.add(t_pbill);
		p.add(l_hbill);
		p.add(t_hbill);
		p.add(b_confirm);
		p.add(b_reset);
		p.setBounds(19, 19,350,300);
		
		this.add(p);
		
	}
	
}
